package com.mask.serviceverificationcode.controller;

import com.mask.internalcommon.DTO.ResponseResult;
import com.mask.internalcommon.DTO.serviceverificationcode.VerifyCodeResponse;
import com.mask.internalcommon.DTO.serviceverificationcode.request.VerifyCodeRequest;
import com.mask.serviceverificationcode.service.VerifyCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "短信接口")
@RestController
@RequestMapping("/verify-code")
@Slf4j
public class VerifyCodeController {

    @Autowired
    VerifyCodeService verifyCodeService;

    @ApiOperation("发送短信验证码")
    @GetMapping("/generate/{identity}/{phoneNumber}")
    public ResponseResult generate(
            @PathVariable("identity") @ApiParam("验证码id") int identity,
            @PathVariable("phoneNumber") @ApiParam("发送验证码手机号") String phoneNumber
            ){
        return verifyCodeService.generate(identity,phoneNumber);

    }

    @ApiOperation("验证短信验证码")
    @PostMapping("/verify")
    public ResponseResult verify(@RequestBody VerifyCodeRequest request) {
        log.info("/verify-code/verify  request:"+ JSONObject.fromObject(request));
        //获取手机号和验证码
        String phoneNumber = request.getPhoneNumber();
        int identity = request.getIdentity();
        String code = request.getCode();

        return verifyCodeService.verify(identity,phoneNumber,code);

    }
}
